home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Acme Filters 2.3.2 folder.sit
/
Acme Filters 2.3.2 folder
/
Acme Filters 2.3.2
/
Acme Filters オ
/
Sources
/
ASCToMac.c
< prev
next >
Wrap
Text File
|
1996-03-02
|
2KB
|
101 lines
/************ I N C L U D E F I L E S *******************************************************/
#include <stdio.h>
#include <string.h>
#include "Acme Filters.h"
#include "ASCToMac.h"
/**********************************************************************************************
* Function Name: ASCToMac
*
* Description: Convert Donna's Smith-Corona word processor files (ASCII format)
* to Mac-readable files (WriteNow text files).
*
* Parameters: iFile - file spec of a file.
*
* Return Value: None.
**********************************************************************************************/
void ASCToMac( FSSpec *iFile )
{
FILE *iFp, *oFp;
char iBuf[kBufSize];
char *c;
FSSpec oFile;
FInfo oInfo;
Boolean topOfDoc = true;
Str255 oName;
// create and open the output file
FSMakeFSSpec( iFile->vRefNum, iFile->parID, iFile->name, &oFile );
if ( oFile.name[0] > kMaxName ) oFile.name[0] = kMaxName;
pstrcat( oFile.name, "¥p.mac" );
pstrcpy( oName, oFile.name ); // save the real name
pstrcpy( oFile.name, kTempFileName ); // use a temporary name
oFp = FSpfopen( &oFile, "wb" );
// set the output file's type and creator
FSpGetFInfo( &oFile, &oInfo );
oInfo.fdType = kTEXTType;
oInfo.fdCreator = kWNCreator;
FSpSetFInfo( &oFile, &oInfo );
// filter the input file
if ( iFp = FSpfopen( iFile, "rb" ) )
{
while ( fgets( iBuf, kBufSize-1, iFp ) != nil )
{
gCancelReq |= Cancel();
ScrollIcon();
c = iBuf;
while ( *c )
{
// replace 5 leading spaces (indented paragraph) with 2 carriage returns and a tab
if ( (strncmp( kFiveSpaces, c, kPSpaces ) == 0) && (*(c+kPSpaces) != kSpace) )
{
if ( topOfDoc )
{
topOfDoc = false;
}
else
{
fputc( kCR, oFp );
fputc( kCR, oFp );
}
fputc( kTab, oFp );
c += kPSpaces;
}
// replace carriage return/line feed with a space
else if ( (*c == kCR) && (*(c+1) == kLF) )
{
fputc( kSpace, oFp );
c += 2;
}
// skip these characters
else if ( (*c == kFF) )
{
c++;
}
// let everything else pass thru
else
{
fputc( *c, oFp );
c++;
}
}
}
}
// close the files
if ( iFp ) fclose( iFp );
if ( oFp ) fclose( oFp );
// set the real filename and deal with any conflicts
while ( FSpRename( &oFile, oName ) == dupFNErr )
oName[oName[0]]++;
TickleParentDir( &oFile );
}